'use strict';

console.log('This server is only for develop and debug, DO NOT USE THIS FOR PRODUCTION.');

const express = require('express');
const httpProxy = require('http-proxy');

const port = 3000;
const app = express();
const proxy = httpProxy.createProxyServer({ target: 'http://localhost:8080' });

proxy.on('error', e => {
  console.log(e);
});

app.use(express.static('public'));

app.all('/api/*', (req, res) => {
  console.log(`proxy to back server: ${req.path}`);
  proxy.web(req, res);
});

app.get('*', (req, res) => {
  console.log(`request path: ${req.path}`);
  res.sendFile(`${__dirname}/public/index.html`);
});

app.listen(port);
console.log(`listening at port ${port}`);
